/**
 *
 * Created by Song,YeWen, 9/18/2011 9:15:05 PM
 *
 */

function validateVideoUrl(ori_url) 
{
    //We use a fake constant duration for video.ca, because it is short UGC, not long duration video
    //TODO: FIXME
    var fcduration = '100'; 
	const URL_GET_FLV = 'http://www.video.ca/media/video/%1.flv';
	var html = download_page(url);
	var videoID = copyBetween(url, 'id=', '&');
    if (!videoID) {
	     // vid not found
	     return 'NotFoundVideo';
	}
	var flv_url = strFormat(URL_GET_FLV, videoID);
	var flv_string = clean_url(flv_url);
    var sb = [];
      
    sb.push(flv_string);
    if(sb.length){
       //var matches = html.match(/<title>(.*?)<\/title>/);
       var matches = html.match(/<title>([\s\S]*?)<\/title>/);
       if(matches){
    	   return 'success_title:' + encodeURIComponent(matches[1])
    	          + '\n video_urls:' + encodeURIComponent(sb)
    	          + '\n seconds:' + Math.round(parseInt(fcduration));
       }
    }
	return 'error:empty_path';
}


/* http://www.video.ca/video.php?id=1868869555&mode=featured */
function js_get_media_url(url) 
{
	const URL_GET_FLV = 'http://www.video.ca/media/video/%1.flv';
	var html = download_page(url);
	var videoID = copyBetween(url, 'id=', '&');
	var flv_url = strFormat(URL_GET_FLV, videoID);
	var flv_string = clean_url(flv_url);

	return flv_string;
}
